1 module targets.ios; 2 import common_macos; 3 import commons; 4 import global_opts; 5 6 7 enum TARGET_TYPE = "simulator"; 8 enum iosArch = 9 [ 10 "simulator" : "x86_64", 11 "hardware" : "arm64" 12 ]; 13 14 string getExtraCommand(string type) 15 { 16 if(type == "simulator") return " -sdk iphonesimulator "; 17 return ""; 18 } 19 20 ChoiceResult prepareiOS(Choice* c, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions cOpts) 21 { 22 string buildTarget = getBuildTarget("ios"); 23 string arch = iosArch[TARGET_TYPE]; 24 prepareAppleOSBase(c,t,input); 25 26 string out_extraLinkerFlags; 27 setupPerCompiler(t, "ldc2", "ios-"~arch, out_extraLinkerFlags); 28 injectLinkerFlagsOnXcode(t, input, out_extraLinkerFlags); 29 if(!("lastUser" in configs)) 30 { 31 configs["lastUser"] = environment["USER"]; 32 configs["firstiOSRun"] = true; 33 } 34 if(environment["USER"] != configs["lastUser"].str) 35 configs["firstiOSRun"] = true; 36 37 appleClean = configs["firstiOSRun"].boolean; 38 39 cached(() => timed(() => outputTemplateForTarget(t, buildTarget))); 40 string codeSignCommand = getCodeSignCommand(t); 41 string extraCommands = getExtraCommand(TARGET_TYPE); 42 43 with(WorkingDir(getHipPath)) 44 { 45 cleanAppleOSLibFolder(); 46 47 if(timed(() => waitDubTarget(t, __MODULE__, DubArguments(). 48 command("build").recipe("ios").deep(true).arch(arch~"-apple-ios12.0").compiler("ldc2").opts(cOpts))) != 0) 49 { 50 t.writelnError("Could not build for AppleOS."); 51 return ChoiceResult.Error; 52 } 53 runEngineDScript(t, "copylinkerfiles.d", 54 "\"--recipe="~buildPath(buildTarget, "dub.json")~"\"", 55 getHipPath("build", "appleos", XCodeDFolder, "libs") 56 ); 57 58 string path = getHipPath("build", "appleos"); 59 string clean = appleClean ? "clean " : ""; 60 61 62 with(WorkingDir(path)) 63 { 64 wait(spawnShell( 65 "xcodebuild -jobs 8 -configuration Debug -scheme 'HipremeEngine iOS' " ~ 66 clean ~ 67 "build CONFIGURATION_BUILD_DIR=\"bin\" "~ 68 codeSignCommand ~ extraCommands ~ 69 "-destination 'platform=iOS Simulator,name=iPhone 14,OS=16.2' " ~ 70 " && cd bin && HipremeEngine.app/Contents/iOS/HipremeEngine") 71 ); 72 } 73 } 74 if(configs["firstiOSRun"].boolean) 75 { 76 configs["firstiOSRun"] = false; 77 updateConfigFile(); 78 } 79 return ChoiceResult.Continue; 80 }